﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Dynamic;

namespace ForzaGT3.Data
{
    public partial class Partner
    {
        public void Insert()
        {
            DataRepositoryFactory.CurrentRepository
                .Create<Partner>(this);
        }

        public void Update()
        {
            DataRepositoryFactory.CurrentRepository
                .Modify<Partner>(this);
        }

        public void Delete()
        {
            DataRepositoryFactory.CurrentRepository
                .Delete<Partner>(this);
        }

        public static Partner GetById(Guid Id)
        {
            return DataRepositoryFactory.CurrentRepository
                .Single<Partner>(x => x.PartnerId == Id);
        }

        public static IEnumerable<Partner> GetAll()
        {
            return DataRepositoryFactory.CurrentRepository
                .Find<Partner>(x => x.IsDeleted == false);
        }

        public static IQueryable<Partner> AdminGetAll(string where,
                                                  List<object> values,
                                                  string sortColumn,
                                                  string sortType,
                                                  int currentPage,
                                                  int pageSize,
                                                  out int totalRecord,
                                                  string booleanColumn = "",
                                                  bool booleanValue = true)
        {
            var data = DataRepositoryFactory.CurrentRepository.GetAll<Partner>().Where(c => c.IsDeleted.Value == false);
            data = data.Where("1=1 " + where, values.ToArray());


            data = data.OrderBy(sortColumn + " " + sortType);

            // Count the total number of records
            totalRecord = data.Count();

            // Get only required page data by skiping the other records
            return data.Skip(pageSize * (currentPage - 1)).Take(pageSize);
        }
    }
}
